package com.vincce.fitness.core.config;

import com.vincce.fitness.core.util.AccountUtil;
import com.vincce.fitness.entity.Account;
import com.vincce.fitness.mappers.core.InitMapper;
import org.springframework.context.annotation.*;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import java.util.List;

/**
 * Created by henry on 4/16/14.
 */
@Configuration
@ComponentScan("com.vincce.fitness")
@EnableWebMvc
@EnableScheduling
@EnableTransactionManagement
public class AppConfig {

	@Bean
	public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
		return new PropertySourcesPlaceholderConfigurer();
	}


	@Bean
	public AccountUtil initAccount(InitMapper initMapper){
		List<Account> list = initMapper.findAccount();
		AccountUtil.initAccount(list);
		return null;
	}


	@Configuration
	@Profile("localhost")
	@PropertySource("classpath:application.localhost.properties")
	static class Localhost {}

	@Configuration
	@Profile("development")
	@PropertySource("classpath:application.development.properties")
	static class Development {}

	@Configuration
	@Profile("production")
	@PropertySource("classpath:application.production.properties")
	static class Production {}

}
